' This script will iterate through all of the layers of a document. If the layer is not a text layer,
' the layer's color values are inverted. If it is the background layer, also rotate, then crop the entire canvas.
' In order to invert the entire document, each layer must be inverted independently (or flattened beforehand).
'
'Before running this script, create a document with a few non-text layers.

Private Sub Command1_Click()

Dim appRef As Photoshop.Application
Dim docRef As Photoshop.Document
Dim cropBounds As Variant
Dim artLayerRef As Photoshop.ArtLayer
Dim strtRulerUnits As PsUnits

Set appRef = New Photoshop.Application

If (appRef.Documents.Count > 0) Then
    strtRulerUnits = appRef.Preferences.RulerUnits
    appRef.Preferences.RulerUnits = psPixels
    
    Set docRef = appRef.ActiveDocument
    Dim offset As Integer
    offset = 20
    cropBounds = Array(20, 20, docRef.Width - offset, docRef.Height - offset)
        
    ' Check each ArtLayer to see what type it is.  Ignore all text layers.
    For Each artLayerRef In docRef.ArtLayers
    
        ' For every non-text layer, invert the contents.
        If (Not artLayerRef.Kind = psTextLayer) Then
        
            ' Need to make the active layer this non-text layer in order to modify the layer.
            ' I want to invert the contents of the entire doc (excluding text), so need to
            ' invert every layer.
            docRef.ActiveLayer = artLayerRef
            docRef.ActiveLayer.Invert
        
            ' The background layer is always non-text, so test to see if it's the background layer.
            ' If it is, then rotate and crop it.
            
            If (artLayerRef.IsBackgroundLayer) Then
                docRef.RotateCanvas 45      ' Rotate 45 degrees
                docRef.Crop cropBounds
            End If
        End If
    Next
    appRef.Preferences.RulerUnits = strtRulerUnits
Else
    MsgBox "Create a document with a few layers before running this script"
End If

End Sub
